home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / parsingcommandline / example6.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  4KB  |  124 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Parsing Command Line        Tulevagen 22       */
  8. /* File:    Example6.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-06                                       */
  11. /* Version: 1.0                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This is a simple example on how to use the ReadItem()  */
  21. /* function. It will simply collect all command line      */
  22. /* arguments (items) and print them each on one line      */
  23. /* together with some extra information. (If the item was */
  24. /* inside quotation marks or not, if it is an equal sign, */
  25. /* if there was an error etc...)                            */
  26.  
  27.  
  28.  
  29. /* Include the dos library definitions: */
  30. #include <dos/dos.h>
  31.  
  32. /* Include information about the argument parsing routine: */
  33. #include <dos/rdargs.h>
  34.  
  35. /* Now we include the necessary function prototype files:         */
  36. #include <clib/dos_protos.h>       /* General dos functions...    */
  37. #include <clib/exec_protos.h>      /* System functions...         */
  38. #include <stdio.h>                 /* Std functions [printf()...] */
  39. #include <stdlib.h>                /* Std functions [exit()...]   */
  40.  
  41.  
  42.  
  43. /* Store up to 50 characters in our string buffer: */
  44. #define BUFFER_SIZE 50
  45.  
  46.  
  47.  
  48. /* Set name and version number: */
  49. UBYTE *version = "$VER: AmigaDOS/ParsingCommandLine/Example6 1.0";
  50.  
  51.  
  52.  
  53. /* Declare an external global library pointer to the Dos library: */
  54. extern struct DosLibrary *DOSBase;
  55.  
  56.  
  57.  
  58. /* Declared our own functions: */
  59.  
  60. /* Our main function: */
  61. int main( int argc, char *argv[] );
  62.  
  63.  
  64. /* Main function: */
  65.  
  66. int main( int argc, char *argv[] )
  67. {
  68.   /* Store the item type value here: (Defined */
  69.   /* in header file "dos/dos.h".)             */
  70.   LONG item_type;
  71.  
  72.   /* Temporary string buffer to store the item name in: */
  73.   UBYTE item_name[ BUFFER_SIZE ];
  74.  
  75.  
  76.  
  77.   /* We need dos library version 37 or higher: */
  78.   if( DOSBase->dl_lib.lib_Version < 37 )
  79.   {
  80.     /* The user's dos library is too old! */
  81.     printf( "This program needs Dos Library V37 or higher!\n" );
  82.  
  83.     /* Exit with an error code: */
  84.     exit ( 20 );
  85.   }
  86.  
  87.  
  88.  
  89.   /* Collect an item: (Store the item name in the string   */
  90.   /* buffer. Up to BUFFER_SIZE characters can be stored,   */
  91.   /* and collect the items from the default input handler. */
  92.   item_type = ReadItem( item_name, BUFFER_SIZE, NULL );
  93.  
  94.   /* As long as we find items we stay in the while loop: */
  95.   while( item_type )
  96.   {
  97.     /* Print the item type: */    
  98.     switch( item_type )
  99.     {
  100.       case ITEM_EQUAL:    printf( "Equal symbol  " ); break;
  101.       case ITEM_ERROR:    printf( "Item ERROR    " ); break;
  102.       case ITEM_UNQUOTED: printf( "Unquoted item " ); break;
  103.       case ITEM_QUOTED:   printf( "Quoted item   " ); break;
  104.       default:            printf( "Unknown item! " );
  105.     }
  106.  
  107.     /* Print the item string: */
  108.     printf( "%s\n", item_name );
  109.     
  110.     /* Collect next item: */    
  111.     item_type = ReadItem( item_name, BUFFER_SIZE, NULL );
  112.   }
  113.  
  114.   /* No more items (item_type is equal to "ITEM_NOTHING"): */
  115.   printf( "No more items!\n" );
  116.  
  117.  
  118.  
  119.   /* The End! */
  120.   exit( 0 );
  121. }
  122.  
  123.  
  124.